content = open('../ref/test_result.txt').read().replace('\t',' ').replace('\n',' ')
segs = content.split(' ')
count = dict()
for s in segs:
    if s in count.keys():
        count[s]+= 1
    else:
        count[s] = 1
def sort_by_value(d):
    items = d.items()
    backitems = [[v[1] , v[0]] for v in items]
    backitems.sort(reverse=True)
    return [backitems[i][1] for i in range(0,len(backitems))]

reverselist = sort_by_value(count)
stopwords = set()
for l in open('../ref/stop.dict').readlines():
    stopwords.add(l.strip())
fout = open('../result/dict.txt','w')
for item in reverselist:
    if item.isdigit()==False and item.isalpha()==False and item not in stopwords:
        fout.write(item+'\t'+str(count[item])+'\n')